/*
 * Filename    : Pool.java
 * Projectname : RamaShinta
 * Date        : Dec 27, 2012 , 11:04:24 AM 
 * 
 */

package com.amikomgamedev.ramashinta.entity;

import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.ui.activity.BaseGameActivity;
import org.andengine.util.adt.pool.GenericPool;

import com.amikomgamedev.ramashinta.Utils;

public class PoolBenda extends GenericPool<Sprite>
{
	private TextureRegion		mTextureRegion;
	private float				x, y, w, h;
	private BaseGameActivity	activity;

	public PoolBenda(float posX, float posY, float width, float height, BaseGameActivity pActivity,
			TextureRegion pTextureRegion)
	{
		// TODO Auto-generated constructor stub
		if (pTextureRegion == null)
		{
			throw new IllegalArgumentException("Texture Kosong");
		}
		mTextureRegion = pTextureRegion;
		x = posX;
		y = posY;
		w = width;
		h = height;
		activity = pActivity;
	}

	@Override
	protected Sprite onAllocatePoolItem()
	{
		// TODO Auto-generated method stub
		return new Sprite(x, y, w, h, mTextureRegion, activity.getVertexBufferObjectManager());

	}

	@Override
	protected void onHandleRecycleItem(Sprite pItem)
	{
		// TODO Auto-generated method stub
		pItem.clearEntityModifiers();
		pItem.clearUpdateHandlers();
		pItem.setVisible(false);
		pItem.detachSelf();
		pItem.reset();
		Utils.TRACE("Pool Benda, onHandleRecycleItem");
	}
}
